import moment from '../../utils/moment';

let app =null;
// console.log('app',app)
Page({
  data: {
    list:[],
    fromId:wx.getStorageSync('userId'),
    time:moment().format()
  },
  handleChat(e) {
    console.log('跳转到聊天页面',e)
    const {avatarurl,nickname,userid} = e.currentTarget.dataset
    wx.navigateTo({
      url: `/pages/socket/socket?avatarUrl=${avatarurl}&&nickName=${nickname}&&userId=${userid}`
    })
  },

  // 判断是否已经进行登录了
  onLoad(){ 
    if(!wx.getStorageSync('isLogin')){
      wx.showModal({
        title: '提示',
        content: '请先进行登录~',
        showCancel: false,
        confirmText: '知道了',
        confirmColor: '#3CC51F',
        success: (result) => {
          if (result.confirm) {
            wx.switchTab({
              url: '/pages/user/user',
            });
          }
        },

      });
    }
  },

  // 获取聊天列表
  onShow(){
    app = getApp();
    this.setData({
      list:app.globalData.chatList
    })
  }
});
